#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int cnt[101] = {0};
    int inp;
    int ans = 0;
    for (int i=1; i<=n; ++i)
    {
        cin >> inp;
        ++cnt[inp];
        if(cnt[inp]>1)cnt[inp]-=2;
    }
    int fir = 0, sec = 0;
    for (int i=1; i<=100; ++i)
    {
        if (cnt[i]==1 && fir == 0) fir = i;
        else if (cnt[i]==1 && fir != 0)
        {
            sec = i;
            ans += sec - fir;
            sec = 0;
            fir = 0;
        }
    }
    cout << ans;
    return 0;
}
